package com.ddyx.service.impl;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

import org.springframework.stereotype.Service;

import com.ddyx.util.template.TemplateMessageUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: TmpMsgListener.java
 * @Description: 这个监听器用于发送模版消息
 * @author: lhj
 * @date: 2018年1月3日
 */
@Slf4j
@Service
public class TmpMsgListener implements MessageListener {
	private ObjectMapper jsonMapper = new ObjectMapper();
	@Override
	public void onMessage(Message msg) {
		if (msg != null) {
			if (msg instanceof TextMessage) {
				TextMessage tMsg = (TextMessage) msg;
				try {
					TemplateMessageUtil.sendTmpMsg(tMsg.getText());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		}

	}
}
